package buttons;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Rectangle;

public class ClickButton extends Button{
	int dx,dy;
	Color normalColor,activeColor,borderColor,textColor;
	String text;
	
	public ClickButton(int X, int Y,int DX, int DY,String t) {
		super(X, Y); this.dx=DX; this.dy=DY; this.text=t;
		this.normalColor=Color.gray; this.activeColor=Color.gray.addToCopy(Color.red); this.borderColor=Color.gray.darker(); this.textColor=Color.gray.brighter();
	}
	public ClickButton(int X, int Y,int DX, int DY,String t,Color nc,Color ac,Color bc, Color tc) {
		super(X, Y); this.dx=DX; this.dy=DY; this.text=t;
		this.normalColor=nc; this.activeColor=ac; this.borderColor=bc; this.textColor=tc;
	}

	public void draw(Graphics g){
		
		g.setColor(normalColor);
		if(clicked){g.setColor(activeColor);}
		g.fill(new Rectangle(x,y,dx,dy)); // background.
		
		g.setColor(borderColor);
		g.draw(new Rectangle(x,y,dx,dy)); // Border
		
		//text
		g.setColor(textColor);
		int tw = (int) g.getFont().getWidth(text);
		int th = (int) g.getFont().getHeight(text);
		g.drawString(text,(float) ((x+(dx/2))-(tw/1.5)),(float) ((y+(dy/2))-(th/1.5)));
		//g.drawString(text,(x+(dx/2)),(y+(dy/2)));
	}

	public void update(int mx, int my, boolean isMouseDown, int delta) {
		if(isMouseDown){ // mouse click?
			if(mx > x && mx < x+dx && my > y && my < y+dy){ // inside range?
				this.clicked=true;
			}
			else{
				this.clicked=false;
			}
		}
		else{
			this.clicked=false;
		}
	}

}
